let v = new Vue({
    el:'#app',
    data:{
        path:'code.jpg',
        username:'',
        password:'',
        code:''
    },
    methods:{
        changeCode:function (event){
            let target = event.target;
            target.src = 'code.jpg?'+new Date();
        },
        login:function (){
            axios({
                url:`common/login`,
                params:{"username":this.username,"password":this.password,"code":this.code}
            }).then(response=>{
                if (response.data.flag){
                    //将用户id储存到cookie中，保存七天
                    $.cookie("userId", response.data.data.id, {path: "/", expires: 7});
                    sessionStorage.setItem("loginUser",JSON.stringify(response.data.data));
                    sessionStorage.setItem("myId",response.data.data.id);
                    location.href = 'common/home';
                }else{
                    layer.msg(response.data.message);
                    this.path='code.jpg?'+new Date();//刷新验证码
                }
            }).catch(error=>{
                layer.msg(error.message);
            })
        }
    }
})